﻿# CMake 最低版本号要求
cmake_minimum_required (VERSION 2.8)

ENABLE_LANGUAGE(CXX)
set(CMAKE_BUILD_TYPE Release)

#设置默认编译类型
if(NOT CMAKE_BUILD_TYPE AND NOT (MSVC_IDE OR XCODE))
  set(CMAKE_BUILD_TYPE Release CACHE STRING "Build type, one of: Release, Debug" FORCE)
endif()


#设置项目名字
PROJECT(XTTO)

message( STATUS "Build type: ${CMAKE_BUILD_TYPE}" )
message( STATUS "Configuration types: ${CMAKE_CONFIGURATION_TYPES}" )

# Detect 64 or 32 bit
if (CMAKE_SIZEOF_VOID_P EQUAL 8)
   # 64-bit project
   SET(64_BIT_OS TRUE)
     MESSAGE("A 64-bit OS detected")
 else()
   SET(64_BIT_OS FALSE)
   MESSAGE("A 32-bit OS detected")
endif()

#设置版本号
SET(MAJOR_VERSION 0)
IF ( NOT VERSION )
   IF ( "${CMAKE_HOST_SYSTEM_NAME}" STREQUAL "Windows" )
      message("windows: Extracting git software version")
      execute_process(COMMAND powershell "(git rev-list --branches HEAD | Measure-Object -line).Lines" OUTPUT_VARIABLE GIT_VERSION WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
   ELSE()
      IF(UNIX OR ${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
         message( STATUS "nix: Extracting git software version" )
      ELSE()
         message( STATUS "unknown platform: extracting git software version" )
      ENDIF()
      execute_process(COMMAND bash "-c" "git rev-list --branches HEAD | wc -l | tr -d ' ' | tr -d '\n'" OUTPUT_VARIABLE GIT_VERSION WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
   ENDIF()

   SET(MINOR_VERSION 1)
   math(EXPR VERSION-BASE ${GIT_VERSION}/255)
   math(EXPR VERSION-REMAINDER ${GIT_VERSION}%255)
   message( STATUS "git build version: ${GIT_VERSION}" )
   message( STATUS "version base: ${VERSION-BASE}" )
   message( STATUS "version remainder: ${VERSION-REMAINDER}" )
   # SET(BUILD_NUMBER ${GIT_VERSION})
   SET(BUILD_NUMBER ${VERSION-BASE})
   SET(VERSION ${MAJOR_VERSION}.${MINOR_VERSION}.${BUILD_NUMBER}-${VERSION-REMAINDER})
ENDIF()
message( STATUS "Software Version: ${VERSION}" )

# Call configure files on ver.h.in to set the version.
# Uses the standard ${VARIABLE} syntax in the file
configure_file(ver.h.in ${PROJECT_SOURCE_DIR}/3rdlib/include/ver.h)
configure_file(common.h.in ${PROJECT_SOURCE_DIR}/3rdlib/include/common.h)
configure_file(xttodefine.h.in ${PROJECT_SOURCE_DIR}/3rdlib/include/xttodefine.h)
configure_file(xttoinlinefun.h.in ${PROJECT_SOURCE_DIR}/3rdlib/include/xttoinlinefun.h)
configure_file(xttotypeinit.h.in ${PROJECT_SOURCE_DIR}/3rdlib/include/xttotypeinit.h)


#引用头文件目录

INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/3rdlib/include/common)

#设置项目目录化
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
set_property(GLOBAL PROPERTY PREDEFINED_TARGETS_FOLDER "CMakeTargets")

#设置if
set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true)

#设置模块化路径
if (POLICY CMP0058)
	# Ninja requires custom command byproducts to be explicit
	cmake_policy(SET CMP0058 NEW)
endif()

set (CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/CMake;${CMAKE_MODULE_PATH}")

#设置预处理器
include(cotire)

#添加三方库
INCLUDE (${CMAKE_SOURCE_DIR}/Options.cmake)

#boost 
FIND_PACKAGE(Boost REQUIRED)
#opencv
FIND_PACKAGE(OpenCV REQUIRED)

if(NOT Boost_FOUND)
    message("Not found Boost")
endif()
if(NOT OpenCV_FOUND)
    message("Not found OpenCV")
endif()

# 添加include目录，本例头文件在./目录下，所以直接取${PROJECT_SOURCE_DIR}/
include_directories(${PROJECT_SOURCE_DIR}/3rdlib/include)

# 添加链接库查找目录，库查找序按照参数顺序从向右查
link_directories(${PROJECT_SOURCE_DIR}/3rdlib/lib)

# 添加子目录（每个子目录下都必须有自已的CMakeLists.txt文件
add_subdirectory(src)
add_subdirectory(test)

message("${Boost_INCLUDE_DIRS}")
message("${Boost_LIBRARY_DIRS}")
